#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void STInit(ST* pst)
{
	assert(pst);
	pst->a = NULL;
	
	pst->capacity = pst->top = 0;
}
void STDestroy(ST* pst)
{
	assert(pst);
	free(pst->a);
	pst->a = NULL;
	pst->capacity = pst->top = 0;

}
void STPush(ST* pst, StDataType x)
{
	assert(pst);
	if (pst->capacity == pst->top)
	{
		int newcapacity = pst->capacity == 0 ? 4 : 2 * pst->capacity;
		StDataType* tmp = (StDataType*)realloc(pst->a, newcapacity * sizeof(StDataType));
		if (tmp == NULL)
		{
			perror("malloc");
			return;
		}
		pst->a = tmp;
		
		pst->capacity = newcapacity;
		

	}
	pst->a[pst->top++] = x;
}
void STPop(ST* pst)
{
	assert(pst && pst->top);
	pst->top--;
}
StDataType STTop(ST* pst)
{
	assert(pst && pst->top);
	return pst->a[(pst->top) - 1];

}
bool STEmpty(ST* pst)
{
	assert(pst );
	return pst->top== 0;

}
int STSize(ST* pst)
{
	assert(pst);
	return pst->top;
}



